package com.zb.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Controller
public class HelloController {

    @Value("${ureport.fileStoreDir}")
    private String fileStoreDir;


    @GetMapping("/say")
    @ResponseBody
    public String helloWorld() {
        return "hello world";
    }

    @GetMapping("/getReportUl")
    @ResponseBody
    public List<String> getReportUl() {
        Path path = Paths.get(fileStoreDir);
        try (Stream<Path> stream = Files.list(path)) {
            return stream.map(p -> p.getFileName().toString()).collect(Collectors.toList());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
